
#ifndef __FILEREADER_HPP__
#define __FILEREADER_HPP__

#include<stdint.h>
#include<string>
#include<stdlib.h>
#include<stdio.h>



class RBSP{
public:
    RBSP();
    ~RBSP();


public:
    uint8_t* RBSPBuf = nullptr;
    int RBSPLen = 0;
};


class EBSP{
public:
    EBSP();
    ~EBSP();

    int GetRBSP(RBSP& rbsp);

    uint8_t* EBSPBuf = nullptr;
    int EBSPLen = 0;
};


class Nalu{
public:
    Nalu();
    ~Nalu();
    int SetBuf(uint8_t* buf, int bufLen);
    int GetEBSP(EBSP& ebsp);
    int ParseRBSP();
    int ParseHeader();
    virtual int Parse();
    
    uint8_t* buf = nullptr;
    int bufLen = 0;
    int StartCodeLen = 0;
    RBSP rbsp;

    int forbidden_zero_bit;
    int nal_ref_idc;
    int nal_unit_type;
    int IdrPicFlag;   

};


class AnnexBReader{
public:
    AnnexBReader(std::string& _fileName);
    ~AnnexBReader();
    int Open();
    int Close();

    int ReadNalu(Nalu& nalu);
private:
    bool CheckStartCode(int& StartCodeLen, uint8_t* bufPtr, int bufLen);
    int ReadFromFile();
    
    char* fileName;
    FILE* f = nullptr;

    bool isEnd = false;
    uint8_t* buffer = nullptr;
    int bufferLen = 0;

};







#endif